let a: any
a = 1
a = '1'
a = true
a = new String('')

let b
b = 1
b = "1"

let c: string
c = a



let d:unknown
d = 99
d = 'string'
d = true
c = d

// 第一种
if (typeof d === 'string') {
    c = d
}

// 第二种（断言）
c = d as string
c = <string>d



let string:string
string = 'hello'
string.toUpperCase() // 无警告

let stringAny:any
stringAny = 'hello'
stringAny.toUpperCase() // 无警告

let stringUnknow:unknown
stringUnknow = 'hello'
stringUnknow.toUpperCase() // 有警告
(stringUnknow as string).toUpperCase()


function demo():never{
    demo()
}
function demo1():never{
    throw new Error()
}



let stringb:string
stringb = '1'

if (typeof stringb === 'string') {
    console.log(stringb.toLocaleLowerCase())
} else {
    console.log(stringb)
}


function call(msg:string):void{
    console.log(msg)
}

function call3():void{
    return;
}
function call4():void{
    return undefined;
}



let aa: object
a = {}
a = Object

// tuple
let arrtuple: [string, number]
arrtuple = ['1',2]

let arrtuple2: [string, boolean?]
arrtuple2 = ['1']

let arrtuple3: [number, ...string[]]
arrtuple3 = [1, '2', '3', '4']


// enum
enum Direction {
    Up = 5,
    Down,
    Left,
    Right
}

function walk(data:Direction):void{
    if (data = Direction.Up) {
        console.log('向上走')
    } else if (data = Direction.Down) {
        console.log('向下走')
    } else if (data = Direction.Left) {
        console.log('向左走')
    } else if (data = Direction.Right) {
        console.log('向右走')
    }
}

enum Direction2 {
    Up = 'up',
    Down = 'down',
    Left = 'left',
    Right = 'right'
}

walk(Direction.Up)


const enum Direction3 {
    Up = 'up',
    Down = 'down'
}

console.log(Direction3.Up)


// type

type Status = number | string

function printStatus(status: Status):void {
    console.log(status)
}

printStatus(404)
printStatus('404')


type Area = {
    height: number,
    width: number
}

type Address = {
    stree: string,
    numebr: number
}

type House = Area & Address

const hose:House = {
    height: 100,
    width: 100,
    stree: 'xxx街道',
    numebr: 1
}